package com.cloud.monitor.sys.controller;

import com.cloud.monitor.sys.service.DataImplementService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author wurj
 * @time 2020/3/9 21:51
 * @description
 */
@RestController
@Configuration
@EnableScheduling
public class DataScratchController {
    @Autowired
    DataImplementService dataImplementService;

    @Scheduled(cron = "0/5 * * * * ?")
    @ApiOperation(value = "插入CPU监控数据")
    @RequestMapping(value = "/insert1",method = RequestMethod.GET)
    public void addCPUValue(){
       dataImplementService.addCPUData();
        System.out.println(new SimpleDateFormat("HH:mm:ss").format(new Date())+"CPU");
    }

    @Scheduled(cron = "0/5 * * * * ?")
    @ApiOperation(value = "插入内存监控数据")
    @RequestMapping(value = "/insert2",method = RequestMethod.GET)
    public void addMemoryValue(){
        dataImplementService.addMemoryData();
        System.out.println(new SimpleDateFormat("HH:mm:ss").format(new Date())+"memory");

    }


    @Scheduled(cron = "0/5 * * * * ?")
    @ApiOperation(value = "插入硬盘监控数据")
    @RequestMapping(value = "/insert3",method = RequestMethod.GET)
    public void addDiskValue(){
        dataImplementService.addDiskData();
        System.out.println(new SimpleDateFormat("HH:mm:ss").format(new Date())+"disk");

    }

    @Scheduled(cron = "0/5 * * * * ?")
    @ApiOperation(value = "插入网络监控数据")
    @RequestMapping(value = "/insert4",method = RequestMethod.GET)
    public void addNetValue(){
        dataImplementService.addNetWorkData(dataImplementService.recData(),dataImplementService.transData());
        System.out.println(new SimpleDateFormat("HH:mm:ss").format(new Date())+"net");

    }

    @Scheduled(cron = "0/5 * * * * ?")
    @ApiOperation(value = "插入IOPS监控数据")
    @RequestMapping(value = "/insert5",method = RequestMethod.GET)
    public void addIOPSValue(){
        dataImplementService.addIOPSData();
        System.out.println(new SimpleDateFormat("HH:mm:ss").format(new Date())+"iops");

    }

}
